package com.ny.service.impl;

import com.ny.dao.StudentDao;
import com.ny.dao.impl.StudentDaoImpl;
import com.ny.entity.Student;
import com.ny.service.StudentService;

import java.sql.SQLException;
import java.util.List;

public class StudentServiceImpl implements StudentService {
    // 业务层的作用：1. 对接dao层的数据进行操作；调用dao层的方法 2. 业务操作；比如对密码加密
    // 1. 创建dao层的对象
    private StudentDao studentDao = new StudentDaoImpl();

    @Override
    public Student login(String name, String password) throws Exception {
        // 2. 调用dao层的方法
        return studentDao.login(name, password);
    }
    @Override
    public int insertStudent(Student student) throws SQLException, ClassNotFoundException {
        // 2. 调用dao层的方法
        return studentDao.insertStudent(student);
    }
    @Override
    public int updateStudent(Student student) throws Exception{
        return studentDao.updateStudent(student);
    }

    @Override
    public List<Student> findAllStudents() throws Exception {
        return  studentDao.findAllStudents();
    }

    @Override
    public Student getStudentById(int id) throws Exception {
        return  studentDao.getStudentById(id);
    }

    @Override
    public int deleteStudent(int id) throws Exception {
        return  studentDao.deleteStudent(id);
    }
}
